<?php
/**
 * 系统配置项 api
 * User: xwc
 * Date: 2023/11/07 17:28
 */

namespace App\OpenApi\AppApi\Sys;

use App\Model\Core\Sys\AppVersionModel;
use App\Model\Core\Sys\SysConfigModel;
use App\Service\Core\Sys\Config\AppVersionService;
use App\Service\OpenApi\AppApi\OpenBaseApi;
use App\Service\ParamsService;

class SysConfigApi extends OpenBaseApi
{
    /**
     * 获取配置信息
     * @return array
     */
    public function getConfig()
    {
        $SysConfigModel = SysConfigModel::getInstance();
        $config_info = $SysConfigModel->getConfig(ParamsService::APP_TIME);
        $hehuan_config_info = $SysConfigModel->getConfig(ParamsService::HEHUAN_PATIENT_POP);
        $config_list = [
            ParamsService::APP_TIME => ['config_name' => ParamsService::$config_item_list[ParamsService::APP_TIME]['name'], 'config_val' => $config_info['config_val']],
            ParamsService::HEHUAN_PATIENT_POP => ['config_name' => ParamsService::$config_item_list[ParamsService::HEHUAN_PATIENT_POP]['name'], 'config_val' => $hehuan_config_info['config_val']],
            ParamsService::MEMBER_AGREEMENT => ['config_name' => ParamsService::$config_item_list[ParamsService::MEMBER_AGREEMENT]['name'], 'config_val' => easy_url('wap', ['config_item' => ParamsService::MEMBER_AGREEMENT])],
            ParamsService::PRIVACY_POLICY => ['config_name' => ParamsService::$config_item_list[ParamsService::PRIVACY_POLICY]['name'], 'config_val' => easy_url('wap', ['config_item' => ParamsService::PRIVACY_POLICY])],
            ParamsService::HEALTH_PRIVACY_POLICY => ['config_name' => ParamsService::$config_item_list[ParamsService::HEALTH_PRIVACY_POLICY]['name'], 'config_val' => easy_url('wap', ['config_item' => ParamsService::HEALTH_PRIVACY_POLICY])],
            ParamsService::INFORMED_CONSENT => ['config_name' => ParamsService::$config_item_list[ParamsService::INFORMED_CONSENT]['name'], 'config_val' => easy_url('wap', ['config_item' => ParamsService::INFORMED_CONSENT])],
            ParamsService::INFORMED_CONSENT_HEHUAN => ['config_name' => ParamsService::$config_item_list[ParamsService::INFORMED_CONSENT_HEHUAN]['name'], 'config_val' => easy_url('wap', ['config_item' => ParamsService::INFORMED_CONSENT_HEHUAN])],
        ];
        return alert_info(0, 'ok', $config_list);
    }

    /**
     * APP版本号
     * @return array
     */
    public function appVersion(): array
    {
        $app_platform = $this->input('app_platform', AppVersionModel::APP_PLATFORM_ANDROID);
        $AppVersionService = AppVersionService::getInstance();
        $version_info = $AppVersionService->getLastOne($app_platform);
        if (empty($version_info)) {
            $version_info = [
                'target_version' => '0.0.0',
                'min_version' => '0.0.0',
            ];
        }
        return alert_info(0, 'ok', $version_info);
    }
}
